'use strict';

const Service = require('egg').Service;

class SettingService extends Service {

  /**
   *
   * @param setData
   * @returns {Bluebird<TInstance[]>}
   */
  async create(setting) {
    const { ctx } = this;
    const result = await ctx.model.Setting.bulkCreate(setting, {
      ignoreDuplicates: true,
      updateOnDuplicate: [ 'key', 'value' ],
    })
    return result;
  }

  /**
   *
   * @returns {Bluebird<TInstance[]>}
   */
  async find() {
    const { ctx } = this;
    const settings = await ctx.model.Setting.findAll();
    return settings;
  }
}
module.exports = SettingService;
